from students.studends.students_service import Stundentservice
from students.studends.stuend import Student


class StudentUI:
    def __init__(self):
        self.studentservice=Stundentservice()

    def search(self):
        condition=input('请输入学生的姓名或学号s=学号，n=姓名：')
        if condition.startswith("s"):
            res=condition.split('=')
            sno=res[1]
            result=self.studentservice.search(sno,None)
            print(result)
        else:
            res = condition.split('=')
            name = res[1]
            return self.studentservice.search(None,name)

    def add(self):
        condent=input('请输入学生信息（学号、姓名、年龄、性别、地址、电话）“注意逗号用英文逗号”：')
        info=condent.split(',')
        s1=Student()
        s1.sno=info[0]
        s1.name=info[1]
        s1.age=info[2]
        s1.sex=info[3]
        s1.address=info[4]
        s1.phone=info[5]
        result=self.studentservice.add(s1)
        if result ==1:
            print('添加成功')
        else:
            print('添加失败')

    def update(self):
        condent=input('请输入学生信息（学号，姓名，年龄，性别，地址，电话，id）“注意逗号用英文逗号”：')
        info=condent.split(',')
        s1=Student()
        s1.sno=info[0]
        s1.name=info[1]
        s1.age=info[2]
        s1.sex=info[3]
        s1.address=info[4]
        s1.phone=info[5]
        s1.id=info[6]
        result=self.studentservice.update(s1)
        if result ==1:
            print('更新成功')
        else:
            print('更新失败')
    def delete(self):
        sno = input('请输入学生学号：')
        result=self.studentservice.delete(sno)
        if result ==1:
            print('删除成功')
        else:
            print('删除失败')


if __name__ == '__main__':
    S1=StudentUI()
    # res=S1.search()
    # print(res)
    S1.delete()
